
package net.ck.hzq.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.alibaba.android.vlayout.layout.SingleLayoutHelper;

import net.ck.hzq.R;

import java.util.ArrayList;
import java.util.List;

import Bean.POSSelectBean;


/**
 *POS查询列表适配器
 * Created by chenjian on 19/2/27
 */
public class PosRecord2Adapter extends DelegateAdapter.Adapter<PosRecord2Adapter.ProfitVH> {

    private final Context mContext;
    private List<POSSelectBean.DataBean.ItemsBean> data = new ArrayList<>();//数据

    public PosRecord2Adapter(Context context, List<POSSelectBean.DataBean.ItemsBean> mdata) {
        mContext = context;
        if (mdata != null) {
            data.addAll(mdata);
        }
    }

    public void setupData(List<POSSelectBean.DataBean.ItemsBean> data) {
        data.clear();
        if (data != null) {
            data.addAll(data);
        }
        notifyDataSetChanged();
    }

    public List<POSSelectBean.DataBean.ItemsBean> getData() {
        return data;
    }

    @Override
    public LayoutHelper onCreateLayoutHelper() {
        return new SingleLayoutHelper();
    }

    @NonNull
    @Override
    public ProfitVH onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new ProfitVH(LayoutInflater.from(mContext).inflate(R.layout.layout_my_device, viewGroup, false));
    }




    @Override
    public void onBindViewHolder(@NonNull ProfitVH holder, int position) {
        POSSelectBean.DataBean.ItemsBean bean = data.get(position);
        if(position == 0){
            holder.handler_info.setVisibility(View.VISIBLE);
        }else{
            holder.handler_info.setVisibility(View.GONE);
        }
        holder.queryArrow.setVisibility(View.GONE);
        holder.index.setText((position+1) + "");
        holder.sn.setText(bean.getPosInstanceSn());
        if ("4".equals(bean.isPassed)) {
            holder.status.setText("已开通");
        } else if ("3".equals(bean.isPassed)) {
            holder.status.setText("");
        } else if ("2".equals(bean.isPassed)) {
            holder.status.setText("审核中");
        } else if ("5".equals(bean.isPassed)) {
            holder.status.setText("已激活");
        }else{
            holder.status.setText("");
        }

        // 来自别人的划拨，深色背景
        if (bean.flowStatus == 2) {
            holder.wrap.setBackgroundColor(mContext.getResources().getColor(R.color.bg_646464));
            holder.index.setTextColor(mContext.getResources().getColor(R.color.white));
            holder.sn.setTextColor(mContext.getResources().getColor(R.color.white));
            holder.status.setTextColor(mContext.getResources().getColor(R.color.white));
            holder.queryArrow.setImageResource(R.drawable.arrow_up_down_white);
        }


    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    class ProfitVH extends RecyclerView.ViewHolder {
        View wrap;
        TextView index;
        TextView sn;
        TextView status;
        ImageView queryArrow;
        View childLayout;
        TextView merchantNumber;
        TextView rate;
        TextView phone;
        TextView name;
        LinearLayout handler_info;
        ProfitVH(@NonNull View itemView) {
            super(itemView);
            handler_info = itemView.findViewById(R.id.handler_info);
            wrap = itemView.findViewById(R.id.wrap);
            index = itemView.findViewById(R.id.index);
            sn = itemView.findViewById(R.id.sn);
            status = itemView.findViewById(R.id.open_status);
            queryArrow = itemView.findViewById(R.id.query_arrow);
            childLayout = itemView.findViewById(R.id.child_layout);
             merchantNumber = itemView.findViewById(R.id.merchant_number);
             rate = itemView.findViewById(R.id.rate);
             phone = itemView.findViewById(R.id.phone);
             name = itemView.findViewById(R.id.name);
        }
    }
}
